<?php echo $header; ?>
<div id="content">
  <div class="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
    <?php } ?>
  </div>
  <?php if ($error_warning) { ?>
  <div class="warning"><?php echo $error_warning; ?></div>
  <?php } ?>
  <div class="box">
    <div class="heading">
      <h1><img src="view/image/product.png" alt="" /> <?php echo $heading_title; ?></h1>
      <div class="buttons"><a onclick="$('#form').submit();" class="button"><?php echo $button_save; ?></a><a onclick="location = '<?php echo $cancel; ?>';" class="button"><?php echo $button_cancel; ?></a></div>
    </div>
    <div class="content">
      <div id="tabs" class="htabs">
        <a href="#tab-general"><?php echo $tab_general; ?></a>
        <a href="#tab-boughttogether"><?php echo $tab_boughttogether; ?></a>
      </div>
      <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form">
        <div id="tab-general">
          <div id="languages" class="htabs">
            <?php foreach ($languages as $language) { ?>
            <a href="#language<?php echo $language['language_id']; ?>"><img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /> <?php echo $language['name']; ?></a>
            <?php } ?>
          </div>
          <?php foreach ($languages as $language) { ?>
          <div id="language<?php echo $language['language_id']; ?>">
            <table class="form">
              <tr>
                <td><span class="required">*</span> <?php echo $entry_name; ?></td>
                <td><input disabled="true" type="text" name="product_description[<?php echo $language['language_id']; ?>][name]" size="100" value="<?php echo isset($product_description[$language['language_id']]) ? $product_description[$language['language_id']]['name'] : ''; ?>" />
                  <?php if (isset($error_name[$language['language_id']])) { ?>
                  <span class="error"><?php echo $error_name[$language['language_id']]; ?></span>
                  <?php } ?></td>
              </tr>
              <tr>
                  <td><?php echo $entry_price; ?></td>
                  <td><input disabled="true" type="text" name="price" value="<?php echo $price; ?>" /></td>
              </tr>
              <tr>
                  <td><?php echo $entry_image; ?></td>
                  <td><div class="image"><img src="<?php echo $thumb; ?>" alt="" id="thumb" /><br />
              </tr>
            </table>
          </div>
          <?php } ?>
        </div>
        <div id="tab-boughttogether">
          <table class="form">
            <tr>
              <td><?php echo $entry_boughttogether; ?></td>
              <td><input type="text" name="boughttogether" value="" /><br />
				<?php echo $text_note; ?>
			  </td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td><div id="product-boughttogether" class="scrollbox">
                  <?php $class = 'odd'; ?>
                  <?php foreach ($product_boughttogether as $product_boughttogether) { ?>
                  <?php $class = ($class == 'even' ? 'odd' : 'even'); ?>
                  <div id="product-boughttogether<?php echo $product_boughttogether['product_id']; ?>" class="<?php echo $class; ?>"> <?php echo $product_boughttogether['name']; ?><img src="view/image/delete.png" />
                    <input type="hidden" name="product_boughttogether[]" value="<?php echo $product_boughttogether['product_id']; ?>" />
                  </div>
                  <?php } ?>
                </div></td>
            </tr>
          </table>
        </div>
      </form>
    </div>
  </div>
</div> 
<script type="text/javascript"><!--
$('input[name=\'boughttogether\']').autocomplete({
	delay: 0,
	source: function(request, response) {
		$.ajax({
			url: 'index.php?route=module/boss_boughttogether/autocomplete&token=<?php echo $token; ?>&filter_name=' +  encodeURIComponent(request.term),
			dataType: 'json',
			success: function(json) {		
				response($.map(json, function(item) {
					return {
						label: item.name,
						value: item.product_id
					}
				}));
			}
		});
		
	}, 
	select: function(event, ui) {
		$('#product-boughttogether' + ui.item.value).remove();
		
		$('#product-boughttogether').append('<div id="product-boughttogether' + ui.item.value + '">' + ui.item.label + '<img src="view/image/delete.png" /><input type="hidden" name="product_boughttogether[]" value="' + ui.item.value + '" /></div>');

		$('#product-boughttogether div:odd').attr('class', 'odd');
		$('#product-boughttogether div:even').attr('class', 'even');
				
		return false;
	},
	focus: function(event, ui) {
      return false;
   }
});

$('#product-boughttogether div img').live('click', function() {
	$(this).parent().remove();
	
	$('#product-boughttogether div:odd').attr('class', 'odd');
	$('#product-boughttogether div:even').attr('class', 'even');	
});
//--></script> 
<script type="text/javascript"><!--
$('#tabs a').tabs(); 
$('#languages a').tabs(); 
$('#vtab-option a').tabs();
//--></script> 
<?php echo $footer; ?>